package com.imooc.shop.utils;

public class Pager {
    //当前页码
    private int pageIndex;
    //一页需要展示多少条数据
    private int pageSize = 3;
    //当前条件下总的数据量
    private int totalCount;
    //总共可以分多少页
    private int totalPages;

    public int getPageIndex() {
        pageIndex = pageIndex <= 0 ? 1 : pageIndex;
        pageIndex = pageIndex >= getTotalPages() ? getTotalPages() : pageIndex;
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPages() {
        //总页数
        //根据总数据量和每页最多展示多少来确定的
        //10条数据3->4页
        //9条数据3 ->3页
        return (this.getTotalCount() - 1) / this.getPageSize() + 1;
    }

    public int getFirstParam() {
        return (this.getPageIndex() - 1) * this.getPageSize();
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
}
